package com.yhd.rabbit.work;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.yhd.rabbit.util.ConnectionUtil;

import java.nio.charset.StandardCharsets;
import java.util.UUID;

/**
 * @author 二十
 * @since 2022/1/14 10:36 上午
 */
public class Sender {

    private static final String QUEUE_NAME= "work_yhd";

    public static void main(String[] args)throws Exception {
        //获取连接
        Connection conn = ConnectionUtil.getConnection();
        //开启通道
        Channel channel = conn.createChannel();
        //声明队列
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);

        for (int i = 0; i < 100; i++) {
            //构建消息
            String message = UUID.randomUUID().toString().replace("-","");
            //推送消息
            channel.basicPublish("",QUEUE_NAME,null,message.getBytes(StandardCharsets.UTF_8));
        }
        //关闭资源
        channel.close();
        conn.close();
    }
}
